#include "TrieExample.h"

#include <iostream>

CONFIG_EXAMPLE(TrieExample)
{
	this->trie = nullptr;
}

TrieExample::~TrieExample()
{
	if (this->trie) delete this->trie;
}

void TrieExample::setUp()
{
	this->trie = new DS::Trie();
	LOG_SUCCESS(Successfully created a new instance of Trie!) << std::endl;
}

void TrieExample::execute()
{
	LOG_INFO___(Inserting words...) << std::endl;
	trie->insert("apple");
	trie->insert("app");
	trie->insert("apple is great!");
	trie->insert("application");
	LOG_INFO___(Searching prefix words...) << std::endl;
	DS::Trie* node = trie->search("");
	if (node) LOG_SUCCESS(Found "") << std::endl;
	else LOG_ERROR__(Not found "") << std::endl;
	node = trie->search("a");
	if (node) LOG_SUCCESS(Found "a") << std::endl;
	else LOG_ERROR__(Not found "a") << std::endl;
	node = trie->search("app");
	if (node) LOG_SUCCESS(Found "app") << std::endl;
	else LOG_ERROR__(Not found "app") << std::endl;
	node = trie->search("apple");
	if (node) LOG_SUCCESS(Found "apple") << std::endl;
	else LOG_ERROR__(Not found "apple") << std::endl;
	node = trie->search("application");
	if (node) LOG_SUCCESS(Found "application") << std::endl;
	else LOG_ERROR__(Not found "application") << std::endl;
	node = trie->search("apple is great!");
	if (node) LOG_SUCCESS(Found "apple is great!") << std::endl;
	else LOG_ERROR__(Not found "apple is great!") << std::endl;
	node = trie->search("apps");
	if (node) LOG_SUCCESS(Found "apps") << std::endl;
	else LOG_ERROR__(Not found "apps") << std::endl;
	node = trie->search(" ");
	if (node) LOG_SUCCESS(Found " ") << std::endl;
	else LOG_ERROR__(Not found " ") << std::endl;
	LOG_INFO___(Searching suffix words...) << std::endl;
	LOG_INFO___(Searching suffix words with "" as the prefix word...) << std::endl;
	DS::SVectorString suf1;
	trie->getSuffix(suf1);
	for (auto& suf : suf1.get())
	{
		LOG_V_SUCCESS(suf) << std::endl;
	}
	LOG_INFO___(Searching suffix words with "a" as the prefix word...) << std::endl;
	node = trie->search("a");
	DS::SVectorString suf2;
	node->getSuffix(suf2);
	for (auto& suf : suf2.get())
	{
		LOG_V_SUCCESS(suf) << std::endl;
	}
}

void TrieExample::tearDown()
{
	delete this->trie;
	this->trie = nullptr;
}
